package cn.openea.perpartner.link.config;

import cn.openea.perpartner.common.auth.config.AuthConfig;
import cn.openea.perpartner.common.core.filter.MyHttpServletRequestFilter;
import cn.openea.perpartner.link.filter.SingleSignOnFilter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Weird077
 * @description TODO
 * @date 2023-02-06 13:28
 */
@Configuration
public class LinkFilterConfig {
    @Value("${sso.url}")
    private String ssoserver;
    @Value("${sso.logout.path}")
    private String ssologoutpath;
    @Value("${sso.excluded.paths}")
    private String ssoexcludedpaths;
    @Bean
    public FilterRegistrationBean<SingleSignOnFilter> ssoFilterRegistration() {
        FilterRegistrationBean<SingleSignOnFilter> registration = new FilterRegistrationBean<>();
        registration.addUrlPatterns("/*");
        registration.setOrder(1);
        registration.setFilter(new SingleSignOnFilter());
        registration.addInitParameter(AuthConfig.SSO_SERVER, ssoserver);
        registration.addInitParameter(AuthConfig.SSO_LOGOUT_PATH, ssologoutpath);
        registration.addInitParameter(AuthConfig.SSO_EXCLUDED_PATHS, ssoexcludedpaths);
        return registration;
    }
    @Bean
    public FilterRegistrationBean<MyHttpServletRequestFilter> httpServletRequestFilterRegistration() {
        FilterRegistrationBean<MyHttpServletRequestFilter> registration = new FilterRegistrationBean<>();
        registration.addUrlPatterns("/*");
        registration.setFilter(new MyHttpServletRequestFilter());
        return registration;
    }
}
